package com.youxue.teachin.common.upload;

import java.util.List;

import com.library.rest.ApiServiceManager;
import com.library.rest.rxjava.RxResultHelper;
import rx.Observable;
import rx.functions.Func1;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-10-07 23:19
 * @version: 9.1.0
 */
public class UploadUserCase {

    final IUploadService mIUploadService;
    public UploadUserCase() {
        Class<IUploadService> claxx = IUploadService.class;
        mIUploadService = ApiServiceManager.getOrCreateApiService(claxx);
    }

    /**
     *@param classify 默认值 001 即可
     * @param suffix 后缀
     * @return
     */
    public Observable<UploadVO> getUploadUrl(String classify, String suffix) {
        return mIUploadService.getUploadUrl(classify, 1, suffix, "image/"+suffix)
            .compose(RxResultHelper.<List<UploadVO>>handleResult())
            .map(new Func1<List<UploadVO>, UploadVO>() {
                @Override
                public UploadVO call(List<UploadVO> uploadVOs) {
                    return uploadVOs.get(0);
                }
            });
    }

    public Observable<List<UploadVO>> getUploadUrl(String classify, int count, String suffix) {
        return mIUploadService.getUploadUrl(classify, count, suffix, "image/"+suffix)
            .compose(RxResultHelper.<List<UploadVO>>handleResult());
    }
}
